package com.ophiux.cs.application.consultBase.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.consultBase.dto.GetFocusDoctorsRequest;
import com.ophiux.cs.application.consultBase.dto.GetFocusDoctorsResponse;
import com.ophiux.cs.application.consultBase.service.IGetFocusDoctorsAppService;
import com.ophiux.cs.application.core.AppResultCode;
import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.application.core.ResultEnum;
import com.ophiux.cs.domain.consultBase.model.valueobj.FocusValueObj;
import com.ophiux.cs.domain.consultBase.model.valueobj.GetFocusDoctorsValueObject;
import com.ophiux.cs.infrastructure.repositories.user.FocusRepository;
import com.ophiux.utils.common.ShiftUtils;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class GetFocusDoctorsAppService implements IGetFocusDoctorsAppService {
	@Autowired
	FocusRepository focusRepository;

	@SuppressWarnings("unchecked")
	@Override
	public Result<List<GetFocusDoctorsResponse>> GetFocusDoctors(GetFocusDoctorsRequest dto) {
		List<GetFocusDoctorsResponse> resp = new ArrayList<GetFocusDoctorsResponse>();
		try {
			/**
			 * 1、验证参数是否允许为空
			 * 2、执行业务 获取返回参数 与 返回签名串
			 */
			if(!dto.isParamValid()) {
				return Result.fail(AppResultCode.FAIL, ResultEnum.requestParamFail.getMsg());
			}
			
			FocusValueObj obj = new FocusValueObj();
			obj = (FocusValueObj) ShiftUtils.objToNewObj(dto, FocusValueObj.class);
			obj.setUSER_ID(dto.getUSER_ID());
			obj.setDoctor();
			
			List<GetFocusDoctorsValueObject> list = focusRepository.getFocusDoctorList(obj);
			resp = ShiftUtils.objToNewObjList(list, GetFocusDoctorsResponse.class);
		} catch (Exception e) {
			log.info("程序异常：",e);
			e.printStackTrace();
			return Result.fail(AppResultCode.EXCEPTION, "程序异常");
		}
		return Result.success(resp);
	}

}
